﻿using System;
using System.Windows.Media.Imaging;
using System.Windows.Media;

namespace DotNetImage.Imaging.TransformFilters
{
    /// <summary>
    /// Rotates image on any angel around the image center.
    /// </summary>
    public class RotateFilter<TPixel, TColorChannel> : FilterBase
    {
        public RotateFilter() { HasMultiThreadingSupport = true; RequiresInternalRefresh = true; }

        [ParameterAttribute(Name = "Angle", DefaultValue = 0, MinValue=0, MaxValue=360)]
        public double RotationAngle { get; set; }

        protected override void ProcessPerPixel(DotNetImage bmp)
        {
            TransformedBitmap tb = new TransformedBitmap();
            tb.BeginInit();
            tb.Source = bmp.BitmapSource;

            var transform = new System.Windows.Media.RotateTransform(angle: 30);
            RotateTransform rotateTransform = new RotateTransform(45, 0.5, 0.5);

            tb.Transform = transform;
            tb.EndInit();  // "Transform must be a combination of scales, flips, and 90 degree rotations"
        }

        protected override void ValidateArguments()
        {
            Validator.ValidateInclusiveRange("Angle", RotationAngle, 0, 360);
        }
    }
}
